package cn.edu.scau.cmi.ema.service.base;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import cn.edu.scau.cmi.ema.domain.Adultertype;
import cn.edu.scau.cmi.ema.domain.Foodtype;

//该服务类提供初始化的事件等
@Service
public class EmaProjectPropertyService extends CmiEmaService{
	
	private boolean isInitial = false;
	private List<Foodtype> mainRootFoodtypes = new ArrayList<Foodtype>();
	private List<Adultertype> mainRootAdultertypes = new ArrayList<Adultertype>();
	
	
	public synchronized EmaProjectPropertyService getEmaProjectProperty() {
		
		if(!isInitial) {
			for(Integer foodtypeId : mainRootFoodtypeIDs) {
				mainRootFoodtypes.add(foodtypeDAO.findFoodtypeById(foodtypeId));
			}
			
			for(Integer adultertypeId : mainRootAdultertypeIDs) {
				mainRootAdultertypes.add(adultertypeDAO.findAdultertypeById(adultertypeId));
			}
			
			isInitial = true;
		}
		return this;
	}
	
	public boolean isInitial() {
		return isInitial;
	}
	public void setInitial(boolean isInitial) {
		this.isInitial = isInitial;
	}
	public List<Foodtype> getFoodtypes() {
		return mainRootFoodtypes;
	}
	public void setFoodtypes(List<Foodtype> foodtypes) {
		this.mainRootFoodtypes = foodtypes;
	}
}